package com.sz.query.controller;

import com.sz.query.entity.Transfer;
import com.sz.query.service.TransferService;
import com.sz.query.vo.PageVO;
import com.sz.query.vo.QueryVO;
import com.sz.query.vo.TransferVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
public class QueryController {

    @Autowired
    TransferService transferService;

    @PostMapping("/query/condition")
    public QueryVO queryByCondtion(@RequestBody TransferVO vo){
        return transferService.getTransfer(vo);
    }

    /**
     * post请求
     * @param no
     * @return
     */
    @PostMapping("/query/dealNo/{no}")
    public Transfer getTransfer(@PathVariable("no") String no){
        /*System.out.println(123);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Transfer transfer =transferService.getTransferByDealNo(no);
        String format = sdf.format(transfer.getDealdate());
        System.out.println(format);*/
        return transferService.getTransferByDealNo(no);
    }

    /**
     * post请求 根据账户id 找到该账户下所有转账详情表的信息
     *
     *
     * @param vo 账户号
     * @return 返回交易表的的List集合
     */
    @PostMapping("/query/acc")
    public QueryVO getTransferByAccId(@RequestBody PageVO vo){
        return transferService.getTransferByAccId(vo);
    }

    /**
     * post请求 根据用户名查找该用户的所有转账详情信息
     * @param vo 用户名
     * @return 返回交易表的List集合
     */
    @PostMapping("/query/username")
    public QueryVO getTransferByName(@RequestBody PageVO vo){
        return transferService.getTransferByName(vo);
    }
//
    @PostMapping("/query/time")
    public List<Transfer> getTransferByTime(@RequestParam("start") String start,@RequestParam("end") String end, @RequestParam("status") Long status){

        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");*/
        /*Date date1 = null;
        Date date2 = null;
        try {
            System.out.println("time");
            date1 = sdf.parse("2020-07-08 00:00:00");
            date2 = sdf.parse("2020-07-09 00:00:00");
        } catch (ParseException e) {
            System.out.println("hahah");
            e.printStackTrace();
        }
        System.out.println(123);*/
        return transferService.getTransferByTime(start,end,status);
    }
    @PostMapping("/query/in/{id}")
    public Double getAccIn(@PathVariable("id") String id){
      return   transferService.getTransferByAccIN(id);
    }

    @PostMapping("/query/out/{id}")
    public Double getAccOut(@PathVariable("id") String id){
        return   transferService.getTransferByAccOut(id);
    }

    @PostMapping("/query/err")
    public QueryVO getQueryErr(@RequestBody  PageVO vo){
        return transferService.getTransferErr(vo);
    }
}
